/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * <p>Project: javaseapp - Qr1
 * <p>Powered by webrx On 2021-08-17 08:53:09
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Qr2 {
    public static void main(String[] args) {
        try {
            //解码 解析图像中的二维码
            BufferedImage i = ImageIO.read(new File("my3.jpg"));
            LuminanceSource source = new BufferedImageLuminanceSource(i);
            BinaryBitmap image = new BinaryBitmap(new HybridBinarizer(source));
            Result result = new MultiFormatReader().decode(image);
            String info = result.getText();
            //info = null info = '' 没有二维码
            System.out.println(info);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
